var orderVue = new Vue({
	el: "body",
	created: function() {
		init();
		_this = this;
		verifyLogin(_this);
	},
	data: {
		payed: [],
		notpayed: [],
		isLoading: true
	},
	methods: {
		my: function() {
			location.href = "./my.html"
		}
	}
})

function loadpayed(a) {
	currentUser = AV.User.current();
	var username = currentUser.attributes.username;
	var user = new AV.Query('Order');
	user.equalTo("username", username);
	var payed = new AV.Query('Order');
	payed.equalTo("type", "payed");
	var query = AV.Query.and(user, payed);
	query.find().then(function(products) {
		for(var i = 0; i < products.length; i++) {
			if(products[i].attributes.img.length > 3) {
				products[i].attributes.img = products[i].attributes.img.slice(0, 3)
			} else {

			}
		}
		a.payed = products;
	}).catch(function(error) {
		console.log(JSON.stringify(error));
	});

}

function loadNotPay(a) {
	currentUser = AV.User.current();
	var username = currentUser.attributes.username;
	var user = new AV.Query('Order');
	user.equalTo("username", username);
	var payed = new AV.Query('Order');
	payed.equalTo("type", "nopay");
	var query = AV.Query.and(user, payed);
	query.find().then(function(products) {
		for(var i = 0; i < products.length; i++) {
			if(products[i].attributes.img.length > 3) {
				products[i].attributes.img = products[i].attributes.img.slice(0, 3)
			} else {

			}
		}
		a.notpayed = products;
		a.isLoading = false
	}).catch(function(error) {
		console.log(JSON.stringify(error));
	});

}

function verifyLogin(a) {
	currentUser = AV.User.current();
	if(currentUser) {
		loadpayed(a)
		loadNotPay(a)
	} else {
		location.href = "login.html?RetUrl=" + getPageUrl()
	}
}